package com.easepal7506a.project.widget;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.easepal7506a.project.Constant.CommmandNum;
import com.easepal7506a.project.R;
import com.easepal7506a.project.interfaces.IProMasaChoose;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 *酸痛检测
 * Created by FHB on 2018/3/26.
 */

public class LayoutStjc_7506 extends ConstraintLayout implements View.OnClickListener{
    private ImageView mIvStjc;//全身舒展

    private IProMasaChoose mAction;
    private MyHandler myHandler;
    public LayoutStjc_7506(Context context) {
        super(context);
    }

    public LayoutStjc_7506(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public void setAction(IProMasaChoose action){
        mAction = action;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        myHandler = new MyHandler(this);
        mIvStjc =  findViewById(R.id.zy_masa_iv_stjc);

        mIvStjc.setOnClickListener(this);

    }

    public void setSelect(int position) {
        myHandler.obtainMessage(100,position).sendToTarget();
    }

    private  class MyHandler extends Handler {
        WeakReference<LayoutStjc_7506> mMainActivityWeakReference;

        MyHandler(LayoutStjc_7506 layoutOne) {
            mMainActivityWeakReference = new WeakReference<>(layoutOne);
        }

        @Override
        public void handleMessage(Message msg) {
            final LayoutStjc_7506 mLayout= mMainActivityWeakReference.get();
            int position = (int)msg.obj;
            Log.e("getDataPer","select"+position);
            if (mLayout != null) {

                mIvStjc.setSelected(position!=-1);
            }
        }
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.zy_masa_iv_stjc) {
            mAction.chooseMassage("酸痛检测", CommmandNum.SUANTJZ);

        }

    }
}
